package com.cn;

import com.cn.controller.OrderController;
import com.cn.controller.ProductController;
import com.cn.controller.ShopCartController;
import com.cn.controller.UserController;
import com.cn.pojo.Product;
import com.cn.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class DemoTest {

    @Autowired
    private UserController userController;

    @Autowired
    private ProductController productController;

    @Autowired
    private ShopCartController shopCartController;

    @Autowired
    private OrderController orderController;

    @Test
    public void test1() {
        //测试添加单个用户
        User user1 = new User(1001, "小厉子", "13307350462", "北京");
        User user2 = new User(1002, "花花", "13407250567", "上海");
        int result = userController.addUser(user1);
        if (result == 1){
            System.out.println(user1.toString() + "用户添加成功");
        }
        else{
            System.out.println(user2.toString() + "用户添加失败");
        }
        result = userController.addUser(user2);
        if (result == 1){
            System.out.println(user2.toString() + "用户添加成功");
        }
        else{
            System.out.println(user2.toString() + "用户添加失败");
        }
    }
    @Test
    public void test2() {
        //测试添加单个商品
        Product product1 = new Product(100001, "晒果果苹果干", 40, "北京", 10000);
        Product product2 = new Product(100002, "老金爆浆黑芝麻丸", 40, "上海", 10000);
        Product product3 = new Product(100003, "澳门厚切猪肉脯", 40, "北京", 10000);
        Product product4 = new Product(100004, "生酮慕斯蛋糕罐罐", 40, "上海", 10000);

        int result = productController.addProduct(product1);
        if (result == 1){
            System.out.println("商品添加成功");
        }
        else{
            System.out.println("商品添加失败");
        }
        result = productController.addProduct(product2);
        result = productController.addProduct(product3);
        result = productController.addProduct(product4);
    }
    @Test
    public void test3() {
        //测试添加订单
        int result = orderController.addOrderByName("小厉子", "澳门厚切猪肉脯", 10);
        if (result == 1){
            System.out.println("订单添加成功");
        }
        else{
            System.out.println("订单添加失败");
        }
    }
    @Test
    public void test4() {
        //测试添加购物车
        int result = shopCartController.addProductToShopCart("花花", "晒果果苹果干", 5);
        if (result == 1){
            System.out.println("添加购物车成功");
        }
        else{
            System.out.println("添加购物车失败");
        }
    }
    @Test
    public void test5() {
        //测试更新购物车
        int result = shopCartController.updateCartItemCount("花花", "晒果果苹果干", 8);
        if (result == 1){
            System.out.println("更新购物车成功");
        }
        else{
            System.out.println("更新购物车失败");
        }
    }
    @Test
    public void test6() {
        //测试删除购物车
        int result = shopCartController.deleteCartItem("花花", "晒果果苹果干");
        if (result == 1){
            System.out.println("删除购物车成功");
        }
        else{
            System.out.println("删除购物车失败");
        }
    }
}
